adminPanel.controller('GradeMappingController',['$scope', '$filter', '$http', '$q','cacheFactory', function($scope, $filter, $http, $q,cacheFactory) {
	
	$q;	
	$scope.gradeList=cacheFactory.getGradeList();
	$scope.termList=cacheFactory.getTermList();
	
	$scope.gradeMappingList=[];
	$scope.showGradeMappingList=false;
	$scope.gradeVo={};
	$scope.isError=false;
	$scope.error="";
	
	$scope.validate=function(){
		
	};
	
	$scope.saveMapping=function(){
		$scope.isError=false;
		$scope.gradeVo.studentId=$scope.searchCriteria.studentEntityId;
		var httpResult=$http.post(BASE_URL+'admin/handleRequest/studentRecord/MAP_GRADE', {"gradeMapping":$scope.gradeVo});
	    httpResult.success(function(data){
	    	if(data.status=='SUCCESS'){
	    		$scope.hideMappingModel();
	    		$scope.getDetails();
	    	}else{
	    		$scope.isError=true;
	    		$scope.error=data.msg;
	    	}
	    });	
	};
	
	$scope.edit=function(row){
		$scope.gradeVo=row;
		$("#mappingModal").modal("show");
	};
	
	$scope.deleteRow=function(row){
		if(!confirm('Are you sure to delete this row?'))
			return;
		$scope.gradeVo=row;
		var httpResult=$http.post(BASE_URL+'admin/handleRequest/studentRecord/DELETE_GRADE_MAPPING', {"gradeMapping":$scope.gradeVo});
	    httpResult.success(function(data){
	    	if(data.status=='SUCCESS'){
	    		$scope.getDetails();
	    	}else{
	    		$scope.isError=true;
	    		$scope.error=data.msg;
	    	}
	    });	
		
	}
	
	$scope.getDetails=function(){
		var httpResult=$http.post(BASE_URL+'admin/handleRequest/studentRecord/GET_GRADE_MAPPING', {"searchCriteria":$scope.searchCriteria});
	    httpResult.success(function(data){
	    	if(data.status=='SUCCESS'){
	    		$scope.gradeMappingList=data.result;
	    		$scope.showGradeMappingList=true;
	    	}else{
	    		$scope.showGradeMappingList=false;
	    	}
	    });
	};
	
	$scope.showMappingModel=function(){
		$scope.gradeVo={};
		$("#mappingModal").modal("show");
	};
	
	$scope.hideMappingModel=function(){
		$("#mappingModal").modal("hide");
	};
}]);